<template>
  <div v-loading="loading" class="app-container">
    <el-select v-model="exchange" placeholder="账户" value-key="id">
      <el-option
        v-for="item in exchangeList"
        :key="item.id"
        :label="item.name"
        :value="item"
      />
    </el-select>
    <el-select v-model="pair" placeholder="交易对">
      <el-option v-for="item in appGlobal.PairList" :key="item" :label="item" :value="item" />
    </el-select>
    <el-button v-if="false" type="primary" @click="getList()">查询</el-button>
    <el-button type="primary" @click="closeLong()">平多</el-button>
    <el-button type="primary" @click="closeShort()">平空</el-button>

    <el-table
      v-if="false"
      :data="exchangeList"
      style="width: 100%"
    >
      <el-table-column
        prop="id"
        label="编号"
        width=""
      />
      <el-table-column
        prop="name"
        label="名称"
        width=""
      />

    </el-table>

  </div>
</template>

<script>
import exchangeApi from '@/api/exchange'
export default {
  data() {
    return {
      loading: false,
      exchange: {},
      pair: '',
      exchangeList: []
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      exchangeApi.getList().then((resp) => {
        this.$message(`列表加载完成`)
        if (resp.data) {
          this.exchangeList = resp.data
        }
      })
        .finally(p => {
          this.loading = false
        })
    },
    closeShort() {
      this.loading = true
      exchangeApi.fastClosing({ exchangeId: this.exchange.id, pair: this.pair, isLong: false }).then(p => {
        this.$message(`平空执行完毕:` + p.data)
      }).finally(() => { this.loading = false })
    },
    closeLong() {
      this.loading = true
      exchangeApi.fastClosing({ exchangeId: this.exchange.id, pair: this.pair, isLong: true }).then(p => {
        this.$message(`平多执行完毕:` + p.data)
      }).finally(() => { this.loading = false })
    }
  }
}
</script>

<style scoped>
.line {
  text-align: center;
}
</style>

